package com.qzdatasoft.mcp.server.demo.prompt;

import com.qzdatasoft.mcp.server.common.AbstractPromptProvider;
import io.modelcontextprotocol.server.McpSyncServerExchange;
import io.modelcontextprotocol.spec.McpSchema;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.function.BiFunction;

@Service
public class GreetingPromptProvider extends AbstractPromptProvider {
    @Override
    protected McpSchema.Prompt getMeta() {
        return new McpSchema.Prompt(
                "greeting",
                "A friendly greeting prompt",
                List.of(new McpSchema.PromptArgument("name", "The name to greet", true))
        );
    }

    @Override
    protected BiFunction<McpSyncServerExchange, McpSchema.GetPromptRequest, McpSchema.GetPromptResult> handler() {
        return (exchange, getPromptRequest) -> {
            String nameArgument = (String) getPromptRequest.arguments().get("name");
            if (nameArgument == null) { nameArgument = "friend"; }
            var userMessage = new McpSchema.PromptMessage(
                    McpSchema.Role.ASSISTANT,
                    new McpSchema.TextContent("Hello " + nameArgument + "! How can I assist you today?")
            );
            return new McpSchema.GetPromptResult("A personalized greeting message", List.of(userMessage));
        };
    }


}
